<?php	
$template['title']='我的点评';
include 'inc/userHead_inc.php';
include_once 'inc/page.inc.php';

if(isset($_GET['content'])){
	skip('comment.php', 'ok', '你真的要删除这条评论吗? <a href="Mymessage.php?confirm=1">确定</a> | <a href="Mymessage.php">取消<a>');

}

if(isset($_COOKIE['youyou']['name']) && isset($_COOKIE['youyou']['pw'])){
	//评论
	if(isset($_GET['comment'])){

		$url = $_POST['url'] .'&id='. $_POST['id'];
		if(empty($_POST['comment_info'])){

			skip($url,'error','评论内容不得为空！');

		}

		//转义入库
		escape($link,$_POST['comment_info']);

		$query='insert into comment(user,content,time) values("'.$_COOKIE['youyou']['name'].'","'.$_POST['comment_info'].'",now())';
		$result=mysqli_query($link, $query);
		if($result){
			skip($url,'ok','恭喜您,评论成功！');
		}else{
			skip($url,'error','评论失败,请稍后重试!');
		}
	}
}else{
		skip('login.php','error','你还没登录，不能评论！');
}

?>

	<div class="info">
		<div class="title">我的点评</div>
		<form action='' method='post'>
			<?php
			echo "<span class='message_ti'>点评内容：</span>";

			//查询是否有点评内容，如果没有就输入图标
			$query="select content from comment where user='".$_COOKIE['youyou']['name']."'";
			$result=execute($link,$query);
			$data=mysqli_fetch_row($result);
			if(!$data){
				echo "<div class='noContent'><img src='img/noContent.png' /><br />您的点评空空如也</div>";
			}else{

				//分页部分
				echo "<div class='pages'>";

					$query="select content from comment where user='".$_COOKIE['youyou']['name']."'";
					$result=execute($link,$query);
					$rows=mysqli_affected_rows($link);
					$query2="select * from userinfo where username='".$_COOKIE['youyou']['name']."'";
					$result2=execute($link,$query2);
					$data2=mysqli_fetch_assoc($result2);

					//调用分页函数
					$page=page($rows,5);

					$query="select * from comment  where user='".$_COOKIE['youyou']['name']."' {$page['limit']}";
					$result=execute($link,$query);
					while ($data=mysqli_fetch_assoc($result)){

						$url=urlencode("message_delete.php?id={$data['id']}&url=comment.php&info=1");
						$return_url=urlencode($_SERVER['REQUEST_URI']);
						$message="你真的要删除本条评论吗？";
						$delete_url="confirm.php?url={$url}&return_url={$return_url}&message={$message}";
						echo "<div class='content2'><div class='headImg'><img src={$data2['headImg']} /></div> <div class='info2'>".$data['content']."</div><a href='$delete_url'>[删除]</a> <div class='time'>".$data['time']."</div> </div>";

					}

					echo "<div class='page_btn'>";
						//出入按钮HTML部分
						echo $page['html'];
					echo "</div>";

				echo "</div>";

			}

		?>
		</form>
	</div>
</div>
<?php
	include 'inc/footer_inc.php';
?>